import json

from flask import Flask, request
from flask_json import FlaskJSON, as_json

app = Flask("demo_fetch")

json_app = FlaskJSON(app)


def get_data(data_name):
    with open(f"../data/{data_name}.json") as fp:
        return json.loads(fp.read())


@app.route("/host", methods=["POST"])
@as_json
def get_host():
    req = request.get_json(force=True)
    page_index = req["page_index"]
    page_size = req["page_size"]
    if page_index > 0:
        return {
            "code": 0,
            "data": []
        }
    return get_data("host")


@app.route("/business", methods=["POST"])
@as_json
def get_business():
    req = request.get_json(force=True)
    page_index = req["page_index"]
    page_size = req["page_size"]
    if page_index > 0:
        return {
            "code": 0,
            "data": []
        }
    return get_data("business")


@app.route("/owner", methods=["POST"])
@as_json
def get_owner():
    req = request.get_json(force=True)
    page_index = req["page_index"]
    page_size = req["page_size"]
    if page_index > 0:
        return {
            "code": 0,
            "data": []
        }
    return get_data("owner")


@app.route("/port", methods=["POST"])
@as_json
def get_port():
    req = request.get_json(force=True)
    page_index = req["page_index"]
    page_size = req["page_size"]
    if page_index > 0:
        return {
            "code": 0,
            "data": []
        }
    return get_data("port")


if __name__ == "__main__":
    app.run("0.0.0.0", 10081)
